package org.jsola.hr.helper;

import org.jsola.hr.dto.ProductTypeAddDTO;
import org.jsola.hr.dto.ProductTypeUpdateDTO;
import org.jsola.hr.entity.ProductTypeDO;
import org.jsola.hr.query.ProductTypeQuery;
import org.jsola.hr.service.IProductTypeService;
import org.jsola.hr.vo.ProductTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 产品分类
 *
 * @author zhr
 */
@Component
public class ProductTypeTestHelper extends BaseTestHelper {
    
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 生成add测试数据
     * @return ProductTypeAddDTO
     */
    public ProductTypeAddDTO getProductTypeAddDTO(){
        ProductTypeAddDTO productTypeAddDTO = new ProductTypeAddDTO();
        productTypeAddDTO.setProductTypeName(getRandomValue("varchar",32));
        return productTypeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ProductTypeUpdateDTO
     */
    public ProductTypeUpdateDTO getProductTypeUpdateDTO(ProductTypeVO productTypeVO){
        return productTypeService.selectDOById(productTypeVO.getId(), SITE_ID).to(ProductTypeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ProductTypeQuery
     */
    public ProductTypeQuery getProductTypeQuery() {
        ProductTypeQuery productTypeQuery = new ProductTypeQuery();
        List<ProductTypeDO> productTypeDOList = productTypeService.list(new ProductTypeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(productTypeDOList)) {
            ProductTypeDO productTypeDO = productTypeDOList.get(0);
            productTypeQuery = productTypeDO.to(ProductTypeQuery.class);
        }
        return productTypeQuery;
    }

    /**
     * 保存示例
     * @return ProductTypeVO
     */
    public ProductTypeVO saveProductTypeExample(){
        ProductTypeAddDTO addDTO = this.getProductTypeAddDTO();
        ProductTypeVO productTypeVO = productTypeService.save(addDTO,buildTokenUser());
        return productTypeVO;
    }


}

